package xyz.msj.hrm.feign.fallback;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import xyz.msj.hrm.doc.CourseDocument;
import xyz.msj.hrm.feign.client.CourseFeignClient;
import xyz.msj.hrm.query.CourseQuery;
import xyz.msj.hrm.util.AjaxResult;

/**
 * 降级方法
 */
@Component
@Slf4j
public class CourseFeignClientFallBack implements FallbackFactory<CourseFeignClient> {
    @Override
    public CourseFeignClient create(Throwable throwable) {
        return new CourseFeignClient() {
            @Override
            public AjaxResult save(CourseDocument courseDocument) {
                log.error("ES保存课程失败，降级了");
                throwable.printStackTrace();

                return AjaxResult.me().setSuccess(false).setMessage("ES保存课程失败，降级了");
            }

            /**
             * 删除es数据
             *
             * @param courseDocument
             * @return
             */
            @Override
            public AjaxResult delete(CourseDocument courseDocument) {
                log.error("ES删除课程失败，降级了");
                throwable.printStackTrace();

                return AjaxResult.me().setSuccess(false).setMessage("ES删除课程失败，降级了");
            }

            /**
             * 根据条件查询课程对象
             *
             * @param courseQuery
             * @return
             */
            @Override
            public AjaxResult search(CourseQuery courseQuery) {
                log.error("ES查询课程失败，降级了");
                throwable.printStackTrace();

                return AjaxResult.me().setSuccess(false).setMessage("ES查询课程失败，降级了");
            }

        };
    }
}
